package com.example.myapplication2;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class loginActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        Button button = (Button) findViewById(R.id.button_login);
        button.setOnClickListener((View.OnClickListener) new MyClickListener());
    }

    class MyClickListener implements View.OnClickListener{

        public void onClick(View v) {
            EditText editText1 = (EditText) findViewById(R.id.editText_account);
            EditText editText2 = (EditText) findViewById(R.id.editText_password);
                String account = editText1.getText().toString();
                String psw = editText2.getText().toString();
                if (account.equals("abc")) {
                    if (psw.equals("123")) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(loginActivity.this);
                        builder.setMessage("登录成功");
                        builder.show();
                        Intent intent = new Intent(loginActivity.this, MainActivity.class);
                        startActivity(intent);
                    } else {
                        AlertDialog.Builder builder = new AlertDialog.Builder(loginActivity.this);
                        builder.setMessage("密码错误");
                        builder.show();
                    }


                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(loginActivity.this);
                    builder.setMessage("用户名错误");
                    builder.show();
                }
            }



    }
}